/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ddnsserver;
import java.util.Vector;
import java.io.File;
/**
 *
 * @author Do Viet Trung
 */
public class FileAndFolder
{
    public static Vector<String> list(String path)
    {
        Vector<String> lst = new Vector<String>();
        String []ls;
        File f = new File(path);
        ls = f.list();

        for(int i = 0; i < ls.length; i++)
        {
            File temp = new File(path + "/" + ls[i]);
            if(temp.isFile() == true)
            {
                lst.add(ls[i]);

            }
            else
            {
                if(temp.isDirectory() == true)
                {
                    String folder = "*" + ls[i];
                    lst.add(folder);
                }
            }
        }
        return lst;
    }
    public static Vector<String>filterFolder(Vector<String> list)
    {
        Vector<String> res = new Vector<String>();
        for(int i = 0; i < list.size(); i++)
        {
            if(list.elementAt(i).startsWith("*"))
            {
               res.add(list.elementAt(i)) ;
            }
        }
        return res;
    }
    
    public static Vector<String> listFolder(String path) {
        Vector<String> lst = new Vector<String>();
        String []ls;
        File f = new File(path);
        ls = f.list();

        for(int i = 0; i < ls.length; i++) {
            File temp = new File(path + "/" + ls[i]);
            if(temp.isDirectory() == true) {
                lst.add(ls[i]);
            }
        }
        
        return lst;
    }

    public static Vector <String> listFile(String path) {
        Vector<String> lst = new Vector<String>();
        String []ls;
        File f = new File(path);
        ls = f.list();

        for(int i = 0; i < ls.length; i++) {
            File temp = new File(path + "/" + ls[i]);
            if(temp.isFile() == true) {
                lst.add(ls[i]);
            }
        }
        
        return lst;
    }
    
    public static String getLastLevel(String path) {
//        String res = "";
//        if(path.endsWith("\\")) {
//            path = JProcess.subString(path, 0, path.length() - 2);
//        }
//
//        int idx = path.lastIndexOf('\\');
//        res = path.substring(idx + 1, path.length());
//
//        return res;

        String res = "";
        if(path.endsWith("\\")) {
            path = JProcess.subString(path, 0, path.length() - 2);
        }

        int idx = path.lastIndexOf('\\');
        res = path.substring(idx + 1, path.length());

        return res;
    }
}
